﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// WeiXinCookie 的摘要说明
/// </summary>
public class WeiXinCookie
{
    public WeiXinCookie()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// 返回USERID
    /// </summary>
    /// <param name="phone"></param>
    /// <param name="userid"></param>
    /// <param name="username"></param>
    /// <returns></returns>
    public static string GetCookie()
    {
        string cookieName = "wx_user_cookie";
        string userId = "";
        //获取用户名密码
        HttpCookie cooks = HttpContext.Current.Request.Cookies[cookieName];
        if (HttpContext.Current.Request.Cookies[cookieName] != null)
        {
            userId = HttpContext.Current.Request.Cookies[cookieName].Values["userid"];
        }
        if (string.IsNullOrEmpty(userId))
        {
            if (HttpContext.Current.Session["userid"] != null)
            {
                userId = HttpContext.Current.Session["userid"].ToString();
            }

        }

        return userId;
    }


    public static void GetCookie(ref string userId, ref string userName, ref string isbuy)
    {
        string cookieName = "wx_user_cookie";
        //获取用户名密码
        HttpCookie cooks = HttpContext.Current.Request.Cookies[cookieName];
        if (HttpContext.Current.Request.Cookies[cookieName] != null)
        {
            userName = HttpContext.Current.Request.Cookies[cookieName].Values["username"];
            userId = HttpContext.Current.Request.Cookies[cookieName].Values["userid"];
            isbuy = HttpContext.Current.Request.Cookies[cookieName].Values["isbuy"];
        }
        else if (HttpContext.Current.Session["userid"] != null)
        {
            userName = HttpContext.Current.Session["username"].ToString();
            userId = HttpContext.Current.Session["userid"].ToString();
            isbuy = HttpContext.Current.Session["isbuy"].ToString();
        }
    }

}